package com.easyattendance.model;
import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Check;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="tbl_user")
public class User implements Serializable{
	
	 @Id
	 @Column(name="user_id",length=15,nullable=false)
	 private String user_id;
	 
	 @GenericGenerator(name="role_id",strategy="foreign")
	 @Column(name="role_id",length=2,nullable=false)
	 private int role_id;
	 
	 @Column(name="password",nullable=false,length=100)
	 private String password;
	 
	 @Column(name="email_id",nullable=false,length=50,unique=true)
	 private String email_id;
	 
	 @Column(name="secret_key",nullable=false,length=50)
	 private String secret_key;
	 
	 @Column(name="enabled",nullable=false,columnDefinition="boolean")
	 private boolean enabled; 
	 
	 @Column(name="isFirstTimeLogin",columnDefinition="boolean",nullable=false)
	 private boolean isFirstTimeLogin;
	 

	/* Many to one mapping */
	
	@ManyToOne
	@JoinColumn(name="role_id",insertable=false,updatable=false,referencedColumnName="role_id")
	private Role role;

	/* One to many mapping */
	
	@OneToOne(mappedBy="user",fetch=FetchType.LAZY)
	@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Section section;
	
	@OneToOne(mappedBy = "user", fetch=FetchType.LAZY)
	@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Teacher teacher;
	
	 public User()
	 {
		 
	 }
 
	 public User(String user_id, int role_id, String password, String email_id,
				String secret_key, boolean enabled, boolean isFirstTimeLogin) {
			super();
			this.user_id = user_id;
			this.role_id = role_id;
			this.password = password;
			this.email_id = email_id;
			this.secret_key = secret_key;
			this.enabled = enabled;
			this.isFirstTimeLogin = isFirstTimeLogin;
			
		}

	 public String getUser_id() {
		return user_id;
	}



	public void setUser_id(String user_id) {
		this.user_id = user_id;
	}



	public int getRole_id() {
		return role_id;
	}



	public void setRole_id(int role_id) {
		this.role_id = role_id;
	}



	public String getPassword() {
		return password;
	}



	public void setPassword(String password) {
		this.password = password;
	}



	public String getEmail_id() {
		return email_id;
	}



	public void setEmail_id(String email_id) {
		this.email_id = email_id;
	}



	public String getSecret_key() {
		return secret_key;
	}



	public void setSecret_key(String secret_key) {
		this.secret_key = secret_key;
	}



	public boolean isEnabled() {
		return enabled;
	}



	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}



	public boolean isFirstTimeLogin() {
		return isFirstTimeLogin;
	}



	public void setFirstTimeLogin(boolean isFirstTimeLogin) {
		this.isFirstTimeLogin = isFirstTimeLogin;
	}



	public Role getRole() {
		return role;
	}



	public void setRole(Role role) {
		this.role = role;
	}



}
